<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
<head>
<title><spring:message code="admin.manageaction.title" /></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>"></script>
<script language="javascript" type="text/javascript">
	
    var f = null;
  
    var totalRows = 0;
         
	function initPage(){
		f = document.f1;
		setData();		 
    }
     
	function selectAll(flag) {
		  
		 for(var i=0;i<totalRows;i++){
			 var rowCbx = document.getElementById("row"+i);
			 rowCbx.checked = flag;
			 selectRow( i , flag );
		    }
	}
	 
	function setFlag( cbx , flag ){
	 cbx.checked = flag;	 
     var flagFieldName = "aclActionApplyList["+ cbx.getAttribute('recNum') +"].flag";
     document.getElementById(flagFieldName).value = (cbx.checked)?1:0;
	}
	function selectRow(rowIndex,flag) { 
		var rowCbx = document.getElementById("row"+rowIndex);  
		var inputs = document.getElementsByTagName("input");
		
		for (var i=0;i<inputs.length;i++) {
			 
			if(inputs[i].type == "checkbox" && inputs[i].getAttribute("rowNum")==rowIndex) { 
			    
			    if(inputs[i].id!=rowCbx.id)
			      {//inputs[i].disabled = !rowCbx.checked;
			      //inputs[i].checked = flag;
			      setFlag(inputs[i],flag);	
			      }   
			}
		}
	}
	function selectCol(flag, colName , forceCheck) { 
		 
		var inputs = document.getElementsByTagName("input");
		for (var i=0;i<inputs.length;i++) {
			 
			if(inputs[i].type == "checkbox" && inputs[i].getAttribute("colNum")==colName) {
				var row = inputs[i].getAttribute("rowNum"); 
				var rowCbx = document.getElementById("row"+row); 

			    setFlag(inputs[i],flag);
				//inputs[i].checked = flag;			   
					 //if(rowCbx.checked)
				       //{inputs[i].checked = flag;} 
			 
				 
			}
		}

		 
		return false;
}
	</script>
</head>
<body onload="initPage();"><%@include file="../top_menu.jsp"%>
<table width=100%>
	<tr>
		<td><c:import url="/WEB-INF/jsp/menu/admin_action_menu.jsp" /></td>
	</tr>
	<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>
</table>


<form action="manage_actions.htm" name="f1" method="post">
<table width=90% class="formTable">

	<tr class="formHeader">
		<td colspan="8"><spring:message code="admin.manageaction.label.actions" /></td>
	</tr>

	<tr>
		<td align="center"><input type="checkbox"
			onclick="selectAll(this.checked)" /></td>

		<td><br />
		<spring:message code="admin.manageaction.label.role" /></td>
		<td><br />
		<spring:message code="admin.manageaction.label.service" /></td>
		<c:set var="colNum" value="0"></c:set>
		<c:forEach var="a" items="${aclActionList}" varStatus="i">
			<td><input type="checkbox"
				onclick="selectCol(this.checked,'${colNum}')" /><br />
			${a.name}</td>
			<c:set var="colNum" value="${colNum + 1}"></c:set>
		</c:forEach>
	</tr>

	<tbody>
		<c:set var="rowNum" value="0"></c:set>
		<c:set var="recNum" value="0"></c:set>
		<c:forEach var="r" items="${roleList}" varStatus="i">
			<c:forEach var="c" items="${aclClassList}" varStatus="j">
				<tr class="tr_record">
					<td align="center"><input type="checkbox" id="row${rowNum}"
						rowNum="${rowNum}" value="0"
						onclick="selectRow(${rowNum},this.checked)" /></td>

					<td><a
						href="<c:url value="/admin/role/edit_role.htm?id=${r.id}"/>">${r.name}</a></td>
					<td><a
						href="<c:url value="/admin/acl/edit_acl_class.htm?id=${c.id}"/>">${c.name}</a></td>

					<c:set var="colNum" value="0"></c:set>
					<c:forEach var="a" items="${aclActionList}" varStatus="i">

						<td><input type="hidden" rowNum="${rowNum}"
							name="aclActionApplyList[${recNum}].roleId" value="${r.id}" /> <input
							type="hidden" rowNum="${rowNum}"
							name="aclActionApplyList[${recNum}].classId" value="${c.id}" />
						<input type="hidden" rowNum="${rowNum}"
							name="aclActionApplyList[${recNum}].actionId" value="${a.id}" />
						<input type="hidden" rowNum="${rowNum}"
							name="aclActionApplyList[${recNum}].flag"
							id="aclActionApplyList[${recNum}].flag" value="0" /> <input
							type="checkbox" colNum="${colNum}"
							id="c${c.id}_r${r.id}_a${a.id}" rowNum="${rowNum}"
							recNum="${recNum}" name="aclActionApplyList[${recNum}].id"
							value="0" onchange="setFlag(this,this.checked)"></input></td>
						<c:set var="colNum" value="${colNum + 1}"></c:set>
						<c:set var="recNum" value="${recNum + 1}"></c:set>
					</c:forEach>


				</tr>

				<c:set var="rowNum" value="${rowNum + 1}"></c:set>
			</c:forEach>
		</c:forEach>

		<tr class="buttonPanel">
			<td colspan="9"><input type="submit" class='ui-button ui-state-default ui-corner-all' value="<spring:message code="admin.manageaction.button.save" />"
				style="width: 100; heigth: 30" /></td>
		</tr>
	</tbody>
</table>
</form>
<script language="javascript" type="text/javascript">
 totalRows = ${rowNum};

 function setData(){
	 <c:forEach var="lr"  items="${aclActionApplyList}">
	   setRecord(${lr.id},${lr.classId},${lr.roleId},${lr.actionId},${lr.flag});
	 </c:forEach> 
	 }
	 
	 function setRecord(id,classId,roleId , actionId , flag ){
		 
		 var domId = 'c'+classId+'_r'+roleId+'_a'+actionId;
		 var cbx = document.getElementById(domId);
		 cbx.value = id;
	 
		 setFlag(cbx , flag);
		}
 </script><%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>